@@ -13,7 +13,6 @@ import android.widget.TextView; |
||
13 | 13 |
import android.widget.Toast; |
14 | 14 |
|
15 | 15 |
import com.android.common.executors.ThreadExecutor; |
16 |
-import ai.pai.client.utils.HttpPostTask; |
|
17 | 16 |
import com.android.common.utils.JSONParseUtils; |
18 | 17 |
import com.android.common.utils.LogHelper; |
19 | 18 |
import com.android.views.swiperefreshrecyclerview.DividerItemDecoration; |
@@ -31,10 +30,11 @@ import ai.pai.client.adapter.HistoryGroupAdapter; |
||
31 | 30 |
import ai.pai.client.beans.GroupInfo; |
32 | 31 |
import ai.pai.client.db.DBService; |
33 | 32 |
import ai.pai.client.db.Preferences; |
33 |
+import ai.pai.client.utils.HttpPostTask; |
|
34 | 34 |
import ai.pai.client.utils.SystemUtils; |
35 | 35 |
import ai.pai.client.utils.UrlContainer; |
36 | 36 |
|
37 |
-public class GroupListActivity extends BaseActivity implements View.OnClickListener,SwipeRefreshLayout.OnRefreshListener{ |
|
37 |
+public class GroupListActivity extends BaseActivity implements View.OnClickListener,SwipeRefreshLayout.OnRefreshListener, HistoryGroupAdapter.GroupActionListener { |
|
38 | 38 |
|
39 | 39 |
private RecyclerView recyclerView; |
40 | 40 |
private SwipeRefreshLayout swipeRefreshLayout; |
@@ -65,6 +65,7 @@ public class GroupListActivity extends BaseActivity implements View.OnClickListe |
||
65 | 65 |
recyclerView.setLayoutManager(layoutManager); |
66 | 66 |
recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST)); |
67 | 67 |
refreshAdapter = new HistoryGroupAdapter(this, groupList); |
68 |
+ refreshAdapter.addGroupActionListener(this); |
|
68 | 69 |
groupAdapter = new HeaderAndFooterRecyclerViewAdapter(refreshAdapter); |
69 | 70 |
recyclerView.setAdapter(groupAdapter); |
70 | 71 |
loadMoreView = LayoutInflater.from(this).inflate(R.layout.view_load_more, recyclerView, false); |
@@ -146,6 +147,8 @@ public class GroupListActivity extends BaseActivity implements View.OnClickListe |
||
146 | 147 |
groupInfo.groupFrom = group.getInt("group_from"); |
147 | 148 |
groupInfo.groupLock = group.getBoolean("group_lock"); |
148 | 149 |
groupInfo.groupAvatarId = group.getInt("group_default_avatar"); |
150 |
+ groupInfo.groupPhotoNum=group.getInt("group_photo_num"); |
|
151 |
+ groupInfo.adminId = group.getString("admin_id"); |
|
149 | 152 |
groupItems.add(groupInfo); |
150 | 153 |
} |
151 | 154 |
} |
@@ -203,4 +206,16 @@ public class GroupListActivity extends BaseActivity implements View.OnClickListe |
||
203 | 206 |
doFetchGroupTask(); |
204 | 207 |
} |
205 | 208 |
|
209 |
+ @Override |
|
210 |
+ public void onGroupDeleted(GroupInfo groupInfo) { |
|
211 |
+ HashMap<String,String> params = new HashMap<String,String>(); |
|
212 |
+ String userId = Preferences.getInstance(this).getUserId(); |
|
213 |
+ if(userId.length()==0){ |
|
214 |
+ return; |
|
215 |
+ } |
|
216 |
+ params.put("admin_id",userId); |
|
217 |
+ params.put("group_id",groupInfo.groupId); |
|
218 |
+ |
|
219 |
+ new HttpPostTask(this,params).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.GROUP_DELETE_URL); |
|
220 |
+ } |
|
206 | 221 |
} |
@@ -8,14 +8,17 @@ import android.view.View; |
||
8 | 8 |
import android.view.ViewGroup; |
9 | 9 |
import android.widget.ImageView; |
10 | 10 |
import android.widget.TextView; |
11 |
+import android.widget.Toast; |
|
11 | 12 |
|
12 | 13 |
import com.android.common.utils.TimeUtils; |
14 |
+import com.android.views.swipeLayout.SwipeLayout; |
|
13 | 15 |
|
14 | 16 |
import java.util.ArrayList; |
15 | 17 |
|
16 | 18 |
import ai.pai.client.R; |
17 | 19 |
import ai.pai.client.activity.GroupActivity; |
18 | 20 |
import ai.pai.client.beans.GroupInfo; |
21 |
+import ai.pai.client.db.Preferences; |
|
19 | 22 |
import ai.pai.client.utils.GroupCreateUtils; |
20 | 23 |
|
21 | 24 |
public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapter.GroupViewHolder> { |
@@ -23,6 +26,7 @@ public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapte |
||
23 | 26 |
private Context context; |
24 | 27 |
private LayoutInflater mInflater; |
25 | 28 |
private ArrayList<GroupInfo> groupList; |
29 |
+ private GroupActionListener listener; |
|
26 | 30 |
|
27 | 31 |
public HistoryGroupAdapter(Context context, ArrayList<GroupInfo> groupList){ |
28 | 32 |
this.context = context; |
@@ -30,7 +34,9 @@ public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapte |
||
30 | 34 |
mInflater = LayoutInflater.from(context); |
31 | 35 |
} |
32 | 36 |
|
33 |
- |
|
37 |
+ public void addGroupActionListener(GroupActionListener listener){ |
|
38 |
+ this.listener = listener; |
|
39 |
+ } |
|
34 | 40 |
@Override |
35 | 41 |
public GroupViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
36 | 42 |
View view = mInflater.inflate(R.layout.history_group_item,parent,false); |
@@ -38,12 +44,14 @@ public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapte |
||
38 | 44 |
viewHolder.avatar = (ImageView)view.findViewById(R.id.iv_group_avatar); |
39 | 45 |
viewHolder.name = (TextView)view.findViewById(R.id.tv_group_name); |
40 | 46 |
viewHolder.time = (TextView)view.findViewById(R.id.tv_group_create_time); |
41 |
- viewHolder.contentView = view; |
|
47 |
+ viewHolder.delete = (TextView)view.findViewById(R.id.tv_trash); |
|
48 |
+ viewHolder.contentView = view.findViewById(R.id.history_group_item_view); |
|
49 |
+ viewHolder.swipeLayout = (SwipeLayout) view; |
|
42 | 50 |
return viewHolder; |
43 | 51 |
} |
44 | 52 |
|
45 | 53 |
@Override |
46 |
- public void onBindViewHolder(GroupViewHolder holder, int position) { |
|
54 |
+ public void onBindViewHolder(final GroupViewHolder holder, int position) { |
|
47 | 55 |
final GroupInfo info = groupList.get(position); |
48 | 56 |
holder.time.setText(TimeUtils.getFormattedTime(info.createTime)); |
49 | 57 |
holder.name.setText(info.groupName); |
@@ -56,6 +64,31 @@ public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapte |
||
56 | 64 |
context.startActivity(intent); |
57 | 65 |
} |
58 | 66 |
}); |
67 |
+ holder.swipeLayout.close(); |
|
68 |
+ holder.delete.setOnClickListener(new View.OnClickListener() { |
|
69 |
+ @Override |
|
70 |
+ public void onClick(View v) { |
|
71 |
+ try{ |
|
72 |
+ if(info.groupPhotoNum>0){ |
|
73 |
+ Toast.makeText(context,R.string.group_photo_not_null,Toast.LENGTH_SHORT).show(); |
|
74 |
+ return; |
|
75 |
+ } |
|
76 |
+ if(!info.adminId.equals(Preferences.getInstance(context).getUserId())){ |
|
77 |
+ Toast.makeText(context,R.string.group_admin_not_me,Toast.LENGTH_SHORT).show(); |
|
78 |
+ return; |
|
79 |
+ } |
|
80 |
+ |
|
81 |
+ }catch (Exception e){ |
|
82 |
+ e.printStackTrace(); |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ groupList.remove(holder.getAdapterPosition()); |
|
86 |
+ notifyItemRemoved(holder.getAdapterPosition()); |
|
87 |
+ if(listener!=null){ |
|
88 |
+ listener.onGroupDeleted(info); |
|
89 |
+ } |
|
90 |
+ } |
|
91 |
+ }); |
|
59 | 92 |
} |
60 | 93 |
|
61 | 94 |
@Override |
@@ -83,9 +116,17 @@ public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapte |
||
83 | 116 |
private TextView name; |
84 | 117 |
private TextView time; |
85 | 118 |
private View contentView; |
119 |
+ private TextView delete; |
|
120 |
+ private SwipeLayout swipeLayout; |
|
86 | 121 |
|
87 | 122 |
public GroupViewHolder(View itemView) { |
88 | 123 |
super(itemView); |
89 | 124 |
} |
90 | 125 |
} |
126 |
+ |
|
127 |
+ public interface GroupActionListener { |
|
128 |
+ |
|
129 |
+ void onGroupDeleted(GroupInfo groupInfo); |
|
130 |
+ |
|
131 |
+ } |
|
91 | 132 |
} |
@@ -17,4 +17,7 @@ public class GroupInfo implements Serializable { |
||
17 | 17 |
public int currentId; |
18 | 18 |
public long lastEnterTime; |
19 | 19 |
|
20 |
+ public int groupPhotoNum; |
|
21 |
+ public String adminId; |
|
22 |
+ |
|
20 | 23 |
} |
@@ -26,6 +26,8 @@ public class UrlContainer { |
||
26 | 26 |
|
27 | 27 |
public static final String GROUP_CREATE_URL = HOST_URL+"g/create"; |
28 | 28 |
|
29 |
+ public static final String GROUP_DELETE_URL = HOST_URL+"g/delete"; |
|
30 |
+ |
|
29 | 31 |
public static final String GROUP_DETAIL_URL = HOST_URL+"g/detail"; |
30 | 32 |
|
31 | 33 |
public static final String GROUP_UPDATE_URL = HOST_URL+"g/update"; |
@@ -1,39 +1,61 @@ |
||
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 |
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
- android:layout_width="match_parent" |
|
4 |
- android:layout_height="56dp" |
|
2 |
+<com.android.views.swipeLayout.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
5 | 3 |
xmlns:app="http://schemas.android.com/apk/res-auto" |
6 |
- android:background="@color/white" |
|
7 |
- android:padding="3dp"> |
|
8 |
- |
|
9 |
- <com.android.views.circleimageview.CircleImageView |
|
10 |
- android:id="@+id/iv_group_avatar" |
|
11 |
- android:layout_width="36dp" |
|
12 |
- android:layout_height="36dp" |
|
13 |
- android:layout_margin="5dp" |
|
14 |
- app:civ_border_width="1dp" |
|
15 |
- app:civ_border_color="@color/pop_bg_color" |
|
16 |
- android:src="@drawable/default_avatar"/> |
|
17 |
- |
|
18 |
- <TextView |
|
19 |
- android:id="@+id/tv_group_name" |
|
20 |
- android:layout_width="wrap_content" |
|
21 |
- android:layout_height="wrap_content" |
|
22 |
- android:layout_marginLeft="8dp" |
|
23 |
- android:layout_toRightOf="@id/iv_group_avatar" |
|
24 |
- android:singleLine="true" |
|
25 |
- android:textColor="@color/dark_grey" |
|
26 |
- android:textSize="14sp" /> |
|
27 |
- |
|
28 |
- <TextView |
|
29 |
- android:id="@+id/tv_group_create_time" |
|
30 |
- android:layout_width="wrap_content" |
|
31 |
- android:layout_height="wrap_content" |
|
32 |
- android:layout_below="@id/tv_group_name" |
|
33 |
- android:layout_marginLeft="8dp" |
|
34 |
- android:layout_marginTop="6dp" |
|
35 |
- android:layout_toRightOf="@id/iv_group_avatar" |
|
36 |
- android:textColor="@color/grey" |
|
37 |
- android:textSize="14sp" /> |
|
38 |
- |
|
39 |
-</RelativeLayout> |
|
4 |
+ android:layout_width="match_parent" |
|
5 |
+ android:layout_height="56dp"> |
|
6 |
+ |
|
7 |
+ <LinearLayout |
|
8 |
+ android:layout_width="80dp" |
|
9 |
+ android:layout_height="match_parent"> |
|
10 |
+ |
|
11 |
+ <TextView |
|
12 |
+ android:id="@+id/tv_trash" |
|
13 |
+ android:layout_width="match_parent" |
|
14 |
+ android:layout_height="match_parent" |
|
15 |
+ android:background="@color/red" |
|
16 |
+ android:gravity="center" |
|
17 |
+ android:text="@string/delete" |
|
18 |
+ android:textColor="@color/white" |
|
19 |
+ android:textSize="18sp" /> |
|
20 |
+ </LinearLayout> |
|
21 |
+ |
|
22 |
+ |
|
23 |
+ <RelativeLayout |
|
24 |
+ android:id="@+id/history_group_item_view" |
|
25 |
+ android:layout_width="match_parent" |
|
26 |
+ android:layout_height="56dp" |
|
27 |
+ android:background="@color/white" |
|
28 |
+ android:padding="3dp"> |
|
29 |
+ |
|
30 |
+ <com.android.views.circleimageview.CircleImageView |
|
31 |
+ android:id="@+id/iv_group_avatar" |
|
32 |
+ android:layout_width="36dp" |
|
33 |
+ android:layout_height="36dp" |
|
34 |
+ android:layout_margin="5dp" |
|
35 |
+ android:src="@drawable/default_avatar" |
|
36 |
+ app:civ_border_color="@color/pop_bg_color" |
|
37 |
+ app:civ_border_width="1dp" /> |
|
38 |
+ |
|
39 |
+ <TextView |
|
40 |
+ android:id="@+id/tv_group_name" |
|
41 |
+ android:layout_width="wrap_content" |
|
42 |
+ android:layout_height="wrap_content" |
|
43 |
+ android:layout_marginLeft="8dp" |
|
44 |
+ android:layout_toRightOf="@id/iv_group_avatar" |
|
45 |
+ android:singleLine="true" |
|
46 |
+ android:textColor="@color/dark_grey" |
|
47 |
+ android:textSize="14sp" /> |
|
48 |
+ |
|
49 |
+ <TextView |
|
50 |
+ android:id="@+id/tv_group_create_time" |
|
51 |
+ android:layout_width="wrap_content" |
|
52 |
+ android:layout_height="wrap_content" |
|
53 |
+ android:layout_below="@id/tv_group_name" |
|
54 |
+ android:layout_marginLeft="8dp" |
|
55 |
+ android:layout_marginTop="6dp" |
|
56 |
+ android:layout_toRightOf="@id/iv_group_avatar" |
|
57 |
+ android:textColor="@color/grey" |
|
58 |
+ android:textSize="14sp" /> |
|
59 |
+ |
|
60 |
+ </RelativeLayout> |
|
61 |
+</com.android.views.swipeLayout.SwipeLayout> |
@@ -246,4 +246,8 @@ |
||
246 | 246 |
<string name="guide_app_join_tour">加入旅行团</string> |
247 | 247 |
|
248 | 248 |
<string name="gather_info">请%1$s前到%2$s集合</string> |
249 |
+ |
|
250 |
+ <string name="group_photo_not_null">该群里已有照片,无法删除</string> |
|
251 |
+ |
|
252 |
+ <string name="group_admin_not_me">您不是该群的管理员,无法删除</string> |
|
249 | 253 |
</resources> |